CC=g++ -g
TARGET_NAME=login.fcg
OUT_DIR=out/
TARGET_DIR=$(OUT_DIR)bin/
OPTS=-I../../../fastcgi/ -I../../../libjson/
LINKS=-lstdc++ -lmysqlclient
# 程序包含的CPP对像
SOURCES=main.cpp \
		Request.cpp

# 处理过程
REQUESTS=../Test.h \
		 ../LoginHandler.h \
		 ../PwdHandler.h \
		 ../GroupHandler.h \
		 ../DeleteGroupHandler.h \
		 ../AddGroupHandler.h \
		 ../UsersHandler.h \
		 ../AddUserHandler.h \
		 ../DeleteUserHandler.h \
		 ../ClearUserHandler.h \
		 ../EmailHandler.h \
		 ../ModifyEmailHandler.h \
		 ../AddEmailHandler.h \
		 ../DeleteEmailHandler.h


OBJECTS=$(subst .cpp,.o,$(SOURCES))
# fastcgi 库
FASTCGI=fcgiapp.o.1 \
		fcgi_stdio.o.1 \
		os_unix.o.1
# libjson　库
LIBJSON=internalJSONNode.o.2 \
		JSONAllocator.o.2 \
		JSONChildren.o.2 \
		JSONDebug.o.2 \
		JSONIterators.o.2 \
		JSONMemory.o.2 \
		JSONNode.o.2 \
		JSONNode_Mutex.o.2 \
		JSONPreparse.o.2 \
		JSONStream.o.2 \
		JSONValidator.o.2 \
		JSONWorker.o.2 \
		JSONWriter.o.2 \
		libjson.o.2

ifeq ($(BUILD), 1)
# 工作在编译目录
all: $(FASTCGI) $(LIBJSON) $(OBJECTS) Handlers.o.0
	$(CC) $(^F) $(LINKS) -o bin/ad.fcgi

else
# 工作在源码目录
all:
	make -C $(OUT_DIR) -f ../Makefile "BUILD=1"
	
endif

# 多处理模块编译
Handlers.o.0: ../Handlers.cpp $(REQUESTS)
	$(CC) -DNDEBUG $(OPTS) -c $< -o $@

# 普通的文件编译
%.o: ../%.cpp
	$(CC) -DNDEBUG $(OPTS) -c $< -o $@

%.o.1: ../../../fastcgi/%.c
	gcc -c $(OPTS) $< -o $@

%.o.2: ../../../libjson/_internal/Source/%.cpp
	g++ -DNDEBUG -c $< -o $@

%.o.3: ../../../libsmtp/%.c
	gcc -c $(OPTS) `pkg-config --cflags glib-2.0` $< -o $@

clean:
	rm $(OUT_DIR)*.o $(OUT_DIR)*.o.0 $(OUT_DIR)*.o.1 $(OUT_DIR)*.o.2 

config:
	mkdir -p $(TARGET_DIR)
